


$(document).ready(function() {
	$("#owl-demo-1").owlCarousel({
		items : 4,
		lazyLoad : true,
		navigation : true
	});
	$("#owl-demo-2").owlCarousel({
		items : 4,
		lazyLoad : true,
		navigation : true
	});
	$("#owl-demo-3").owlCarousel({
		items : 4,
		lazyLoad : true,
		navigation : true
	});
	getTop();
	ajaxPost();
	getCenterText("中二病");
	getMostheat();
	getLastUpdate();
	
});



function getTop(){
	var params;
	ajaxpost("/videomessage/getFirstPage.do", params, function(data){
	
		for (var i in data) {
			var obj=data[i];
			var text="<div class="+"most-viewed"+">"+
	         "<div class="+"col-2-4"+">"+
	         "<div class="+"wrap-col"+">"+
	     	 "<div class="+"zoom-container"+">"+
	     	 "<a href="+"/videomessage/player.do?id=+"+obj.videoid+">"+
			 "<span class="+"zoom-caption"+">"+
			 "<i class="+"icon-play fa fa-play"+">"+
			 "</i>"+
			 "</span>"+
	         "<img src='/images/4.jpg'/>"+
			 "</a>"+
	     	 "</div>"+
			 "</div>"+
		     "</div>"+
		     "</div>";
           console.log("12333323333");
		  $("#top").append(text);
		}
	});
}





function ajaxPost(){

	var params;
	ajaxpost("/videomessage/getFirstPage_Top.do", params,function(data){
		var text=1;
		var action;
		var tbody=1;
		var i=0;
		var n=1;
		for(i in data){
			//注意img标签的src可以用''包括起来
			var obj=data[i];
			text+="<div class="+"zoom-container"+">"+
			"<a href="+"/videomessage/player.do?id=+"+obj.videoid+">"+
			"<span class="+"zoom-caption"+">"+ 
			"<i class='icon-play fa fa-play'></i>"+
			"</span> " +
			"<img src='/images/1.jpg'/>"+
			"</a>"+
			"</div>";
			if((parseInt(i)+parseInt(n))%2==0){
				text=text.substring(1);

				tbody+="<div class="+"col-1-4"+">"+
				"<div class="+"wrap-col"+">"+
				text+
				"</div>"+
				"</div>";
				text=1;
			}

		}

		tbody=tbody.substring(1);
         
		$("#tbody").append(tbody);
	});
		
}


function getCenterText(parmes){
	ajaxpost("/videomessage/getFirstPage_anime.do",parmes,function(data){
		var text=1;
        for(var i in data){
        var obj=data[i];
        var videoid=obj.videoid;
        var videoname=obj.videoname;
        var hot=obj.hot;
        var releasetime=obj.releasetime;
        text+="<div class="+"item wrap-vid"+">"+
		"<div class="+"zoom-container"+">"+
		"<a href="+"/videomessage/player.do?id=+"+videoid+">"+
		"<span class="+"zoom-caption"+">"+
		"<i class="+"icon-play fa fa-play"+">"+
		"</i>"+
		"</span>"+ 
		"<img src='/images/1.jpg'/>"+
		"</a>"+
		"</div>"+
		"<h3 class="+"vid-name"+">"+
		"<a href="+'#'+">"+videoname+"</a>"+
		"</h3>"+
		"<div class="+"info"+">"+
		"<h5>"+
		"By"+ 
		"<a href="+'#'+">"+"Kelvin"+"</a>"+
		"</h5>"
		"<span>"+"<i class="+"fa fa-calendar"+"></i>"+releasetime+"</span>"+
		"<span>"+"<i class="+"fa fa-heart"+" id="+"hot"+">"+hot+"</i>"+"</span>"+
		"</div>"+
		"</div>";
            	  
        }
        
        text=text.substring(1);
        
        $("#owl-demo-1").append(text);
        
	});
}



/**单个展示页面显示最新的视频**/
function getLastUpdate(){

	var params=null;
	ajaxpost("/videomessage/getLastUpdate.do", params,function(data){
       

        for (var i in data) {
			var obj=data[i];
			var videoid=obj.videoid;
			var releasetime=obj.releasetime;
			var hot=obj.hot;
			var videoname=obj.videoname;

			var text ="<div class="+"post wrap-vid"+">"+
			"<div class="+'zoom-container'+">"+
			"<a href="+"/videomessage/player.do?id=+"+obj.videoid+">"+
			"<span class="+"zoom-caption"+">"+ 
			"<i class='icon-play fa fa-play'></i>"+
			"</span>"+
			"<img src='/images/4.jpg'/>"+
			"</a>"+
			"</div>"+
			"<div class="+"wrapper"+">"+
			"<h5 class="+"vid-name"+">"+
			"<a href="+"#"+">"+videoname+"</a>"+
			"</h5>"+
			"<div class="+"info"+">"+
			"<h6>"+
			"By"+
			"<a href="+'#'+">"+
			"Admins"+
			"</a>"+
			"</h6>"+
			"<span>"+
			"<i class="+"fa fa-calendar"+">" +
			"</i>"+releasetime+
			"</span>"+ 
			"<span>"+
			"<i class="+"fa fa-heart"+">"+
			"</i>"+hot+
			"</span>"+
			"</div>"+
			"</div>"+
			"</div>";
			
			$("#LatestPosts").append(text);
		
        }
	
		
	});
}



/**获取单个页面最火的三个视频**/
function getMostheat(){
	var params=null;
	ajaxpost("/videomessage/getMostheat.do", params,function(data){
        /**图片ajax代码不需要""拼接**/
		for (var i in data) {
			var obj=data[i];
			var videoid=obj.videoid;
			var releasetime=obj.releasetime;
			var hot=obj.hot;
			var videoname=obj.videoname;
			var text="<div class="+"row"+">"+
			"<div class="+"wrap-vid"+">"+
			"<div class="+"zoom-container"+">"+
			"<a href="+"/videomessage/player.do?id="+videoid+">"+
			"<span class="+"zoom-caption"+">"+ 
			"<i class='icon-play fa fa-play'></i>"+
			"</span>" +
			"<img src='/images/1.jpg'/>"+
			"</a>"+
			"</div>"+
			"<h3 class="+"vid-name"+">"+videoname+"</h3>"+
			"<div class="+"info"+">"+
			"<h5>"+
			"By"+ 
			"<a href="+'#'+">"+"Admins"+
			"</a>"+
			"</h5>"+	
			"<span>"+
			"<i class="+'fa fa-calendar'+">"+
			"</i>"+releasetime+
			"</span>"+ 
			"<span>"+
			"<i class="+'fa fa-heart'+">" +
			"</i>"+hot+
			"</span>"+
			"</div>"+
			"</div>"+
			"</div>";
			$("#Mostheat").append(text); 
		}	
	});


}
